<template>
<el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dept">
        <!-- <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-button type="primary" @click="addOrUpdateHandle()">{{
            $t("add")
          }}</el-button>
        </el-form-item>
      </el-form> -->
        <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
            <el-form-item>
                <el-date-picker v-model="value1" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-select v-model="dataForm.state" placeholder="状态" clearable>
                    <el-option :value="item.val" v-for="item in status" :key="item.val" :label="item.name">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-input v-model="dataForm.respondent" placeholder="被投诉方姓名" clearable></el-input>
            </el-form-item>
            <el-form-item>
                <el-input v-model="dataForm.complainant" placeholder="投诉方姓名" clearable></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="getDataList()">{{ $t("query") }}</el-button>
            </el-form-item>
            <el-form-item>
                <el-button v-if="$hasPermission('scenic:commcomplaint:export')" type="primary" @click="exportHandle()">导出</el-button>
            </el-form-item>
        </el-form>
        <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle" style="width: 100%">
            <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
            <el-table-column prop="complainant" label="投诉方姓名" align="center" min-width="150"></el-table-column>
            <el-table-column prop="respondent" label="被投诉方姓名" align="center" min-width="150"></el-table-column>
            <el-table-column prop="orderId" label="投诉单号" align="center" min-width="150"></el-table-column>
            <el-table-column prop="respondentPhone" label="被投诉方联系方式" align="center" min-width="150"></el-table-column>
            <el-table-column prop="complainantPhone" label="投诉方联系方式" align="center" min-width="150"></el-table-column>
            <el-table-column prop="content" label="投诉内容" header-align="center" align="center" :show-overflow-tooltip="true" min-width="120"></el-table-column>

            <el-table-column prop="state" label="状态" header-align="center" align="center">
                <template slot-scope="scope">
                    {{
              scope.row.state == 0
                ? "处理中"
                : scope.row.state == 1
                ? "已解决"
                : "已取消"
            }}
                </template>
            </el-table-column>
            <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>
            <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
                <template slot-scope="scope">
                    <el-button v-if="$hasPermission('scenic:commcomplaint:update')&&scope.row.state == 0" type="text" size="small" @click="changeStatus(scope.row)">已解决</el-button>
                    <el-button  v-if="$hasPermission('scenic:commcomplaint:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
        </el-pagination>
    </div>
</el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
export default {
    mixins: [mixinViewModule],
    data() {
        return {
            mixinViewModuleOptions: {
                getDataListURL: "/scenic/commcomplaint/page",
                deleteURL: "/scenic/commcomplaint",
                getDataListIsPage: true,
                deleteIsBatch: true,
                exportURL: "/scenic/commcomplaint/export",
            },
            value1: [],
            status: [{
                    val: 0,
                    name: '处理中'
                },
                {
                    val: 1,
                    name: '已解决'
                },
                {
                    val: 2,
                    name: '已取消'
                }
            ],
            dataForm: {},
        };
    },
    watch: {
        value1(newval, oldval) {
            if (newval) {
                if (newval != oldval) {
                    this.dataForm.startDate = newval[0];
                    this.dataForm.endDate = newval[1];
                }
            } else {
                this.dataForm.startDate = '';
                this.dataForm.endDate = '';
            }
        }
    },
    components: {},
    methods: {
        changeStatus(item) {
            this.$confirm("确认该操作?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                })
                .then(() => {
                    item.state = 1;
                    this.$http.put("/scenic/commcomplaint", item).then((res) => {
                        console.log(res);
                        if (res.data.code !== 0) {
                            return this.$message.error(res.data.msg);
                        }
                        this.$message({
                            message: this.$t("prompt.success"),
                            type: "success",
                            duration: 500,
                            onClose: () => {
                                this.getDataList();
                            },
                        });
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消修改",
                    });
                });
        },
    },
};
</script>
